package com.itheima.d5_map;

import java.util.*;
import java.util.function.BiConsumer;

/*
     目标：掌握Map集合的常用方法(重点)
        public V put(K key,V value)	添加元素
        public int size()	获取集合的大小
        public void clear()	清空集合
        public boolean isEmpty()	判断集合是否为空，为空返回true , 反之
        public V get(Object key)	根据键获取对应值
        public V remove(Object key)	根据键删除整个元素
        public  boolean containsKey(Object key)	判断是否包含某个键
        public boolean containsValue(Object value)	判断是否包含某个值
        public Set<K> keySet()	获取全部键的集合
        public Collection<V> values()	获取Map集合的全部值
 */
public class MapTest2 {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("张三", "BB");
        map.put("王五", "EE");
        map.put("赵六", "DD");
        map.put("宋七", "AA");
        map.put("武松", "BB");
        map.put("林冲", "CC");
        System.out.println(map);

//        System.out.println(map.size());
//        System.out.println(map.isEmpty());
//        map.clear();
//        System.out.println(map.isEmpty());

//        System.out.println(map.remove("武松"));
        System.out.println(map.containsKey("貂蝉"));
        System.out.println(map.containsKey("王五"));

        System.out.println(map.containsValue("EE"));
        System.out.println(map.containsValue("TT"));

//        Set<String> strings = map.keySet();
//        for (String s : strings) {
//            System.out.println(s);
//        }

//        Collection<String> values = map.values();
//        for (String v : values) {
//            System.out.println(v);
//        }

//        System.out.println("=====================");
//        Set<String> keys = map.keySet();
//        for (String k : keys) {
//            String v = map.get(k);
//            System.out.println(k+":"+v);
//        }


        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String k = entry.getKey();
            String v = entry.getValue();
            System.out.println(k+":"+v);
        }








/*        Set<String> keys = map.keySet();
        Collection<String> values = map.values();

        ArrayList<String > k = new ArrayList<>(keys);
        ArrayList<String > v = new ArrayList<>(values);

        System.out.println(k);
        for (int i = 0; i < k.size(); i++) {
            System.out.println(k.get(i) +":"+ v.get(i));
        }*/


        System.out.println("+++++++++++++++++++++++++++++++");
/*        map.forEach(new BiConsumer<String, String>() {
            @Override
            public void accept(String string, String string2) {
                System.out.println(string+":" +string2);
            }
        });*/

        map.forEach((string, string2) -> System.out.println(string+":" +string2));



    }
}
